var pageNum=1,pageSize=8,pageTotal=0;
var pageNum2=1,pageSize2=5,pageTotal2=0;
var pageNum3=1,pageSize3=4,pageTotal3=0;
$(function(){
	var basicMsgRecruiter_statei = $("#basicMsgRecruiter_statei").val();
	if(basicMsgRecruiter_statei==1){
		alert("招聘状态下为禁用，不可查看");
			history.back(-1);
	}
	
	$("#alterBut").click(function(){
		$("#alterDiv").hide();
	});
	
	loadDeliverResumeMessage();
});
function showDeliverResume(){
	$("#deliverResumeTable").show();
	$("#interviewInvitation").hide();
	$("#showDeliverResumeDetailMessage").hide();
	$("#showDetailMessage").hide();
	$("#zhaoPinMessage").hide();
	$("#top-font").text("投递简历");
	loadDeliverResumeMessage();
}
function loadDeliverResumeMessage(){
	utilAjax("/deliver_resume/queryAllDeliverMessageByRecruiter_id","pageNum="+pageNum+"&pageSize="+pageSize,"get",
			function(data){
		pageNum = data.pageNum;
		pageSize = data.pageSize;
		pageTotal = data.pages;
		parseDeliverResumeMessage(data.list);
	});
}
function parseDeliverResumeMessage(lists){
	var deliverCon = "";
	if(lists!=""){
		deliverCon += "<tr class='info text-info'><th>求职者</th>"+
						"<th>招聘岗位</th><th>面试状态</th>"+
						"<th>下载状态</th><th>操作</th></tr>";
		$.each(lists,function(i,d){
			var dr_download_state = "";
			if(d.dr_download_state==1){dr_download_state="暂不能下载"}
			if(d.dr_download_state==2){dr_download_state="<a href='/deliver_resume/downLoad?fileName="+d.doc_res.doc_title+"'>下载</a>"}
			deliverCon+="<tr>" +
						"<td>"+d.doc_res.basic.basic_name+"</td>" +
						"<td>"+d.rec_title+"</td>" +
						"<td>"+(d.dr_state==2?"面试邀请中":"暂未审核")+"</td>" +
						"<td>"+dr_download_state+"</td>" +
						"<td>" +
							"<input type='button' onclick='updateDeliveDr_state("+d.dr_id+",1)' value='拒绝面试' class='btn btn-primary'> " +
							"<input type='button' onclick='updateDeliveDr_state("+d.dr_id+",2)' value='邀请面试' class='btn btn-primary'> " +
							"<input type='button' value='查看详细' onclick=DeliverResumeDetailMessage("+d.doc_res.basic.basic_id+") class='btn btn-primary'>"+
						"</td>"+
					"</tr>";
		});
		deliverCon+= "<tr><td colspan='6' align='center'>当前页:"+pageNum+"/总页数:"+pageTotal+"</td></tr>";
		deliverCon+= "<tr>" +
				"<td colspan='6'>" +
				"<input type='button' value='首页' onclick=changeDeliverResumePage(this) class='btn btn-primary'> " +
				"<input type='button' value='上一页' onclick=changeDeliverResumePage(this) class='btn btn-primary'> " +
				"<input type='button' value='下一页' onclick=changeDeliverResumePage(this) class='btn btn-primary'> " +
				"<input type='button' value='末页' onclick=changeDeliverResumePage(this) class='btn btn-primary'> " +
			"</td></tr>";
	}else{
		deliverCon+="<tr><td width='1300' align='center'><font size='6' color='red'>暂无投递</font></td></tr>";
	}
	$("#deliverResumeTable").html(deliverCon);
}
function changeDeliverResumePage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum=1;
		loadDeliverResumeMessage();
		break;
	case "上一页":
		if(pageNum>1){
			pageNum--;
			loadDeliverResumeMessage();
		}	
		break;
	case "下一页":
		if(pageNum<pageTotal){
			pageNum++;
			loadDeliverResumeMessage();
		}
		break;
	case "末页":
		pageNum=pageTotal;
		loadDeliverResumeMessage();
		break;
	}
}
function DeliverResumeDetailMessage(basic_id){
	$("#showDeliverResumeDetailMessage").show();
	$("#deliverResumeTable").hide();
	utilAjax("/basic_information/queryByBasic_id","basic_id="+basic_id,"post",
			function(data){
		$("#res_name2").text(data.recMessage.res_name);
		$("#res_gender2").text((data.recMessage.res_gender==1?"男":"女"));
		$("#res_date2").text(data.recMessage.res_date);
		$("#res_photo2").attr("src","/image/"+data.recMessage.res_photo);
		$("#res_pa2").text(data.recMessage.res_pa);
		$("#res_jeMin2").text(data.recMessage.res_jeMin);
		$("#res_jeMax2").text(data.recMessage.res_jeMax);
		$("#res_we2").text(data.recMessage.res_we);
		$("#res_pe2").text(data.recMessage.res_pe);
		
		var res_ee = "";
		if(data.recMessage.res_ee==1){res_ee="在校生";}
		if(data.recMessage.res_ee==2){res_ee="应届生";}
		if(data.recMessage.res_ee==3){res_ee="一年以内";}
		if(data.recMessage.res_ee==4){res_ee="1-5年";}
		if(data.recMessage.res_ee==5){res_ee="5-10年";}
		if(data.recMessage.res_ee==6){res_ee="10年以上";}
		$("#res_ee2").text(res_ee);
		
		var rec_workYears = "";//设置经验年限
		if(data.recMessage.res_workYear==1){rec_workYears = "在校生"}
		if(data.recMessage.res_workYear==2){rec_workYears = "应届生"}
		if(data.recMessage.res_workYear==3){rec_workYears = "一年以内"}
		if(data.recMessage.res_workYear==4){rec_workYears = "1-5年"}
		if(data.recMessage.res_workYear==5){rec_workYears = "5-10年"}
		if(data.recMessage.res_workYear==6){rec_workYears = "10年以上"}
		$("#res_workYear2").text(rec_workYears);
		
		
	});
}
	
function backDeliverResumeTable(){
	$("#showDeliverResumeDetailMessage").hide();
	$("#deliverResumeTable").show();
}

function updateDeliveDr_state(dr_id, dr_state){
	utilAjax("/deliver_resume/updateDeliveDr_state",
			"dr_id="+dr_id+"&dr_state="+dr_state,
			"post",
			function(flag){
		if(flag){
			$("#alterContent").text("操作成功");
			loadDeliverResumeMessage();
		}else{
			$("#alterContent").text("操作失败");
		}
		loadAlter();
	});
}

function showInterviewInvitation(){
	$("#deliverResumeTable").hide();
	$("#interviewInvitation").show();
	$("#showDeliverResumeDetailMessage").hide();
	$("#top-font").text("面试邀请");
	loadInterviewInvitationMessage();
}
function loadInterviewInvitationMessage(){
	utilAjax("/basic_information/queryByJudge_deliver_resumAndLikeRec_address",
			"pageNum="+pageNum2+"&pageSize="+pageSize2,"get",
			function(data){
		pageNum2 = data.pageNum;
		pageSize2 = data.pageSize;
		pageTotal2 = data.pages;
		parseInterviewInvitationMessage(data.list);
	});
}
function parseInterviewInvitationMessage(lists){
	var interCon ="";
	if(lists!=""){
		interCon+="<tr class='info text-info'><td align='center'><input type='checkbox' onclick=checkedBox(this)></td><th>编号</th><th>昵称</th>"+
			"<th>手机</th><th>头像</th>"+
			"<th>求职状态</th><th>地址</th><th>操作</th></tr>";
		$.each(lists,function(i,l){
			interCon+="<tr>" +
						"<td><input type='checkbox' value='"+l.basic_id+"' name='checkId'></td>"+
						"<td>"+l.basic_id+"</td>" +
						"<td>"+l.basic_name+"</td>" +
						"<td>"+l.basic_phone+"</td>" +
						"<td><img src='/image/"+l.basic_photo+"' width='50' height='50'></td>" +
						"<td>"+(l.basic_job_state==1?'不接收本地区招聘公司的个人信息浏览':'接收本地区招聘公司的个人信息浏览')+"</td>" +
						"<td>"+l.rec_address+"</td>"+
						"<td>" +
								"<input type='button' value='查看详细' onclick=lookDetailMessage("+l.basic_id+") class='btn btn-primary'>" +
						"</td>"
					"</tr>";
		});
		interCon+= "<tr><td colspan='8' align='center'>当前页:"+pageNum2+"/总页数:"+pageTotal2+"</td></tr>";
		interCon+= "<tr>" +
				"<td colspan='2'><input type='button' onclick='MianShiyaoQing()' value='发送面试邀请' class='btn btn-primary'></td><td colspan='6' style='padding-right:15%;'>" +
				"<input type='button' value='首页' onclick=changeInterviewInvitationPage(this) class='btn btn-primary'> " +
				"<input type='button' value='上一页' onclick=changeInterviewInvitationPage(this) class='btn btn-primary'> " +
				"<input type='button' value='下一页' onclick=changeInterviewInvitationPage(this) class='btn btn-primary'> " +
				"<input type='button' value='末页' onclick=changeInterviewInvitationPage(this) class='btn btn-primary'> " +
			"</td></tr>";
	}else{
		interCon+="<tr><td width='1300' align='center'><font size='6' color='red'>暂未找到符合要求的应聘者</font></td></tr>";
	}
	$("#interviewInvitation").html(interCon);
}
function changeInterviewInvitationPage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum2=1;
		loadInterviewInvitationMessage();
		break;
	case "上一页":
		if(pageNum2>1){
			pageNum2--;
			loadInterviewInvitationMessage();
		}	
		break;
	case "下一页":
		if(pageNum2<pageTotal2){
			pageNum2++;
			loadInterviewInvitationMessage();
		}
		break;
	case "末页":
		pageNum2=pageTotal2;
		loadInterviewInvitationMessage();
		break;
	}
}
function lookDetailMessage(basic_id){
	$("#interviewInvitation").hide();
	$("#showDetailMessage").show();
	utilAjax("/basic_information/queryByBasic_id","basic_id="+basic_id,"post",
			function(data){
		$("#res_name").text(data.recMessage.res_name);
		$("#res_gender").text((data.recMessage.res_gender==1?"男":"女"));
		$("#res_date").text(data.recMessage.res_date);
		$("#res_photo").attr("src","/image/"+data.recMessage.res_photo);
		$("#res_pa").text(data.recMessage.res_pa);
		$("#res_jeMin").text(data.recMessage.res_jeMin);
		$("#res_jeMax").text(data.recMessage.res_jeMax);
		$("#res_we").text(data.recMessage.res_we);
		$("#res_pe").text(data.recMessage.res_pe);
		
		var res_ee = "";
		if(data.recMessage.res_ee==1){res_ee="在校生";}
		if(data.recMessage.res_ee==2){res_ee="应届生";}
		if(data.recMessage.res_ee==3){res_ee="一年以内";}
		if(data.recMessage.res_ee==4){res_ee="1-5年";}
		if(data.recMessage.res_ee==5){res_ee="5-10年";}
		if(data.recMessage.res_ee==6){res_ee="10年以上";}
		$("#res_ee").text(res_ee);
		
		var rec_workYears = "";//设置经验年限
		if(data.recMessage.res_workYear==1){res_workYears = "在校生"}
		if(data.recMessage.res_workYear==2){rec_workYears = "应届生"}
		if(data.recMessage.res_workYear==3){rec_workYears = "一年以内"}
		if(data.recMessage.res_workYear==4){rec_workYears = "1-5年"}
		if(data.recMessage.res_workYear==5){rec_workYears = "5-10年"}
		if(data.recMessage.res_workYear==6){rec_workYears = "10年以上"}
		
		$("#res_workYear").text(res_workYears);
	});
}

function backLookMessage(){
	$("#interviewInvitation").show();
	$("#showDetailMessage").hide();
}
//点击全选/全不选复选框
function checkedBox(op){
	var check = $(op).prop("checked");
	if(check==true){
		$("input[type='checkbox']").prop("checked",true);
	}else{
		$("input[type='checkbox']").prop("checked",false);
	}
}
//发送面试邀请，复选框状态为true的信息
function MianShiyaoQing(){
	var checkVal = [];
	$("input[name='checkId']:checked").each(function(){
		checkVal.push($(this).val());
	});
	var ids= $.param({"ids":checkVal},true);
	if(ids!=""){
		$("#zhaoPinMessage").show();
		$("#interviewInvitation").hide ();
		$("#showDetailMessage").hide();
		utilAjax("/recruitment_msg/queryAllRecMsgByRecruiter_id","pageNum="+pageNum3+"&pageSize="+pageSize3,"get",
				function(data){
			pageNum3 = data.pageNum;
			pageSize3 = data.pageSize;
			pageTotal3 = data.pages;
			parseAllRecMsg(data.list);
		});
	}else{
		alert("请选择求职者");
	}
	
	
}

function parseAllRecMsg(lists){
	var zpCon = "";
	if(lists!=""){
		zpCon+="<tr><td colspan='16' align='center' style='border:none;'><h2>所有招聘信息</h2></td></tr>" +
			"<tr><th>序号</th><th>标题</th><th>联系电话</th><th>薪资范围</th>"+
			"<th>招聘岗位</th><th>招聘者姓名</th><th>工作年限</th>"+
			"<th>学历要求</th><th>福利待遇</th><th>状态</th>"+
			"<th>审核状态</th><th>公司名</th><th>公司地址</th><th>操作</th>"+
		"</tr>";
		$.each(lists,function(i,r){
			var rec_workYear = "";//设置经验年限
			if(r.rec_workYear==1){rec_workYear = "在校生"}
			if(r.rec_workYear==2){rec_workYear = "应届生"}
			if(r.rec_workYear==3){rec_workYear = "一年以内"}
			if(r.rec_workYear==4){rec_workYear = "1-5年"}
			if(r.rec_workYear==5){rec_workYear = "5-10年"}
			if(r.rec_workYear==6){rec_workYear = "10年以上"}
			var rec_qualification = "";//设置学历要求
			if(r.rec_qualification==1){rec_qualification = "初中及以下"}
			if(r.rec_qualification==2){rec_qualification = "中专/技校"}
			if(r.rec_qualification==3){rec_qualification = "高中"}
			if(r.rec_qualification==4){rec_qualification = "大专"}
			if(r.rec_qualification==5){rec_qualification = "本科"}
			if(r.rec_qualification==6){rec_qualification = "硕士"}
			if(r.rec_qualification==7){rec_qualification = "博士"}
			var rec_msg_check_state = "";
			if(r.rec_msg_check_state==1){rec_msg_check_state = "通过"}
			if(r.rec_msg_check_state==2){rec_msg_check_state = "未通过"}
			if(r.rec_msg_check_state==3){rec_msg_check_state = "审核中"}
			zpCon += "<tr>" +
					"<td>"+r.rec_id+"</td>" +
					"<td>"+r.rec_title+"</td>" +
					"<td>"+r.rec_phone+"</td>" +
					"<td>"+r.rec_pay_min+"--"+r.rec_pay_max+"</td>" +
					"<td>"+r.rec_duty+"</td>" +
					"<td>"+r.rec_name+"</td>" +
					"<td>"+rec_workYear+"</td>" +
					"<td>"+rec_qualification+"</td>" +
					"<td><textarea class='form-control' rows='2' readonly='readonly'>"+r.rec_welfare+"</textarea></td>" +
					"<td>"+(r.rec_msg_state==1?"上架":"下架")+"</td>" +
					"<td>"+rec_msg_check_state+"</td>" +
					"<td>"+r.rec_company_name+"</td>" +
					"<td>"+r.rec_company_address+"</td>" +
					"<td>" +
						"<input type='button' value='确认选择该招聘信息' onclick=affirm("+r.rec_id+") class='btn btn-primary'>" +
					"</td>" +
				"</tr>";
		});
		zpCon+= "<tr><td colspan='14' align='center'>当前页:"+pageNum3+"/总页数:"+pageTotal3+"</td></tr>";
		zpCon+= "<tr>" +
				"<td colspan='14' style='align:center;'>" +
				"<input type='button' value='首页' onclick=changeZhaoPingMessagePage(this) class='btn btn-primary'> " +
				"<input type='button' value='上一页' onclick=changeZhaoPingMessagePage(this) class='btn btn-primary'> " +
				"<input type='button' value='下一页' onclick=changeZhaoPingMessagePage(this) class='btn btn-primary'> " +
				"<input type='button' value='末页' onclick=changeZhaoPingMessagePage(this) class='btn btn-primary'> " +
			"</td></tr>" +
			"<tr><td align='center' colspan='14'><input type='button' value='返回' class='btn btn-primary' onclick='backUp()'></td></tr>";
	}else{
		zpCon+= "<tr><td align='center' width='1470'><font size='6' color='red'>暂无招聘信息</font></td></tr>";
	}
	$("#zhaoPinMessage").html(zpCon);
}
function affirm(rec_id){
	var checkVal = [];
	$("input[name='checkId']:checked").each(function(){
		checkVal.push($(this).val());
	});
	var ids= $.param({"ids":checkVal},true);
	if(ids!=""){
		utilAjax("/deliver_resume/touDi",ids+"&rec_id="+rec_id,"post",function(data){
			$("#alterContent").text(data.msg);
			if(data.msg=="发送成功"){
				window.location.href="/view/job/jobInterview.jsp";
			}
			loadAlter();
		});
	}

}
function backUp(){
	$("#zhaoPinMessage").hide();
	$("#interviewInvitation").show();
}
function changeZhaoPingMessagePage(op){
	var butCon = $(op).val();
	switch(butCon){
	case "首页":
		pageNum3=1;
		MianShiyaoQing();
		break;
	case "上一页":
		if(pageNum3>1){
			pageNum3--;
			MianShiyaoQing();
		}	
		break;
	case "下一页":
		if(pageNum3<pageTotal3){
			pageNum3++;
			MianShiyaoQing();
		}
		break;
	case "末页":
		pageNum3=pageTotal3;
		MianShiyaoQing();
		break;
	}
}

function utilAjax(url,data,type,success){
	$.ajax({
		url:url,
		data:data,
		dataType:'json',
		type:type,
		success:success,
		error:function(){
		}
	});
}
function loadAlter(){
	var alterCon = $("#alterContent").text();
	if(alterCon!=""){
		$(".alterDiv").show();
		var interval = setInterval(function(){
			$(".alterDiv").hide();
			$("#alterContent").text("");
			clearInterval(interval);
		},3000);
	}
	$("#alterBut").click(function(){
		$(".alterDiv").hide();
	});
}